class Solution(object):
    def removeElement(self, nums, val):
        """
        :type nums: List[int]
        :type val: int
        :rtype: int
        """
        """
        快慢指针法
        """
        # # 创建两个指针
        fast = 0
        slow = 0
        size = len(nums)
        while fast < size:
            if nums[fast] != val:
                nums[slow] = nums[fast]
                slow += 1
            fast += 1
        return slow

        # """相向双指针法"""
        # left = 0
        # right = len(nums) - 1
        # while left <= right:
        #     while left <= right and nums[left] != val:
        #         left += 1
        #     while left <= right and nums[right] == val:
        #         right -= 1
        #     if left < right:
        #         nums[left] = nums[right]
        #         right -= 1
        #         left += 1
        #
        # return left


if __name__ == '__main__':
    nums = [1, 2, 3, 4, 5, 3, 6, 7]
    val = 3
    solu = Solution()
    result = solu.removeElement(nums, val)
    print(result)
